/**
 * @author : dormi330
 * @since : 2021/1/20/0020
 */
public class Main03 {
    private static int count;

    public static void main(String[] args) {

        Thread loop = new Thread(() -> {
            while (true) {
                if (Thread.interrupted()) {
                    System.out.println("interrupted " + Thread.currentThread().getName());
                    // Thread.currentThread().interrupt();
                    // break;
                }
                if (count > 100) {
                    break;
                }
                // do sth
                System.out.println(Thread.currentThread().getName() + ":" + count++);
            }

        });
        loop.setName("loop-thread");

        // the main thread
        loop.start();
        loop.interrupt();
    }
}

/*
输出：
interrupted loop-thread
loop-thread:0
loop-thread:1
loop-thread:2
loop-thread:3
...
loop-thread:100

 */